<template>
  <div class="search">
    <f-form ref="form" :action="api.dept" :form-key="this.formItem.deptId">
      <f-form-item label="部门名称" name="deptName" :required="true" :value="formItem.deptName"/>
      <f-form-item label="部门编码" name="deptCode" :required="true" :value="formItem.deptCode"/>
      <f-form-item label='部门负责人' placeholder='请选择部门负责人' name='saleManName' :readOnly='true' :value.sync='formItem.saleManName' :trigger-change='true'>
        <a-tooltip slot='addonBefore' placement='top' title='点击图标选择部门负责人'>
          <a-icon type='user' style='cursor:pointer' @click='openSaleManModal' />
        </a-tooltip>
      </f-form-item>
      <f-form-item label="业务类型" type='select' name="deptType"  :required="true" :data='api.busCommon.deptType' :value="formItem.deptType"/>
      <f-form-item label="省级" type='radio' name="proLevel" data-type="number"  :required='true' :data='api.busCommon.proLevel' :value="formItem.proLevel"/>
      <f-form-item label="结算标准" type="number"  name="settleRate" dataType="number" :precision="3" :value="formItem.settleRate"/>
    </f-form>
    <select-dept-man-modal ref='saleManModal' @onSelectChange='onSelectSaleManChange' :selectType='3' title='招募人选择'></select-dept-man-modal>
  </div>
</template>
<script>
  import api from './js/api'
  import SelectDeptManModal from "@/views/module/haiying/components/select_deptman_modal"
  export default {
    name: 'deptForm',
    props: {},
    data() {
      return {
        refs: this.$refs,
        api: Object.assign(api, this.api),
        isAdd: true,//是否是添加模式
        loaded: false,//是否加载完成
        params: {
          deptId: ''
        },
        formItem: this.getFormItem()
      }
    },
    methods: {
      getFormItem() {
        return {
          deptId: '',
          deptName: '',
          deptType: "ZY",
          proLevel:0,
          deptCode: '',
          reputation: 120,
          reputationAmount: 1200000
        }
      },
      //表单赋值
      setData(data) {
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        if (data && data.deptId) {
          let params = {
            deptId: data.deptId
          }
          this.params = params
          this.refs['form'].getDetails(params, (data) => {
            this.formItem = data
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.loaded = true
        }
      },
      /**
       * 选择招募人
       */
      openSaleManModal() {
        this.$refs["saleManModal"].open({
          selectType: 3
        })
      },
      /**
       * 业务员选择回调
       */
      onSelectSaleManChange(selectedRowKeys, selectedRows) {
        this.$refs.form.getForm().setFieldsValue({ "saleManName": selectedRows[0].saleManName })
        this.formItem.saleManName = selectedRows[0].saleManName
        this.formItem.salemanId = selectedRowKeys[0]
        this.$forceUpdate()
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs.form.submit({
          salemanId:this.formItem.salemanId,
          isFlp:1
        }, callback)
      }
    },
    created() {
    },
    components: {SelectDeptManModal}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
